#include "stdafx.h"
#include "FadeInOut.h"

using namespace MomogenkyouContent;

FadeInOut::FadeInOut()
:	m_bEnded(true), m_bProceed(true),
	m_fElapsedTime(0),
	m_fFadeInTime(0), m_fVisibleTime(0), m_fFadeOutTime(0),
	m_fAlphaValue(0), m_iPhase(0)
{
}

FadeInOut::~FadeInOut()
{

}

void FadeInOut::Start(const float & fIn, const float & fStay, const float & fOut)
{
	m_iPhase = 0;
	m_fAlphaValue	= 0;
	m_fElapsedTime	= 0;
	m_fFadeInTime	= fIn;
	m_fVisibleTime	= fStay;
	m_fFadeOutTime	= fOut;
	m_bEnded = false;
}

void FadeInOut::Update(const float & fInterval)
{
	if(m_bEnded) return;

	m_fElapsedTime += fInterval;
	
	switch(m_iPhase)
	{
	case 0:
		
		//	Fade in
		(m_fAlphaValue < 1.0f)? m_fAlphaValue += (1.0f / m_fFadeInTime) * fInterval : m_fAlphaValue = 1.0f;
		if(m_fElapsedTime > m_fFadeInTime)
			m_iPhase++;
		break;

	case 1:
		//	Stay Visible
		m_fAlphaValue = 1.0f;
		if(m_fElapsedTime > m_fFadeInTime + m_fVisibleTime && m_bProceed)
			m_iPhase++;
		break;

	case 2:
		//	Fade Out
		(m_fAlphaValue > 0)? m_fAlphaValue -= (1.0f / m_fFadeOutTime) * fInterval : m_fAlphaValue = 0.0f;
		if(m_fAlphaValue == 0)
			m_bEnded = true;
		break;
	}
}